/*
 * @Description: 缓存
 * @Author: xinqiao lxq1990.0716@qq.com
 * @Date: 2023-10-12
 * @LastEditors: xinqiao lxq1990.0716@qq.com
 * @LastEditTime: 2024-04-24
 */
// const { envVersion } = uni.getAccountInfoSync().miniProgram
const envVersion = 'develop'

/** openid_key */
const OPENID_KEY = `${envVersion}-openid`
/** 获取openid */
const getOpenid = () => uni.getStorageSync(OPENID_KEY)
/** 设置openid */
const saveOpenid = (openid: string) => uni.setStorageSync(OPENID_KEY, openid)
/** 移除openid */
const removeOpenid = () => uni.removeStorageSync(OPENID_KEY)

/** token_key */
const TOKEN_KEY = `${envVersion}-token`
/** 获取token */
const getToken = () => uni.getStorageSync(TOKEN_KEY)
/** 设置token */
const saveToken = (token: string) => uni.setStorageSync(TOKEN_KEY, token)
/** 移除token */
const removeToken = () => uni.removeStorageSync(TOKEN_KEY)

/** refreshToken_key */
const REFRESHTOKEN_KEY = `${envVersion}-refresh-token`
/** 获取refreshToken */
const getRefreshToken = () => uni.getStorageSync(REFRESHTOKEN_KEY)
/** 设置refreshToken */
const saveRefreshToken = (refreshToken: string) => uni.setStorageSync(REFRESHTOKEN_KEY, refreshToken)
/** 移除refreshToken */
const removeRefreshToken = () => uni.removeStorageSync(REFRESHTOKEN_KEY)

/** loginCode_key */
const LOGINCODE_KEY = `${envVersion}-login-code`
/** 获取loginCode */
const getLoginCode = () => uni.getStorageSync(LOGINCODE_KEY)
/** 设置loginCode */
const saveLoginCode = (loginCode: string) => uni.setStorageSync(LOGINCODE_KEY, loginCode)
/** 移除loginCode */
const removeLoginCode = () => uni.removeStorageSync(LOGINCODE_KEY)

/** userId_key */
const USERID_KEY = `${envVersion}-userid`
/** 获取userId */
const getUserId = () => uni.getStorageSync(USERID_KEY)
/** 设置userId */
const saveUserId = (loginCode: number) => uni.setStorageSync(USERID_KEY, loginCode)
/** 移除userId */
const removeUserId = () => uni.removeStorageSync(USERID_KEY)

export {
  getLoginCode,
  getOpenid,
  getRefreshToken,
  getToken,
  getUserId,
  removeLoginCode,
  removeOpenid,
  removeRefreshToken,
  removeToken,
  removeUserId,
  saveLoginCode,
  saveOpenid,
  saveRefreshToken,
  saveToken,
  saveUserId,
}
